

package basic;
import Logger.MainLogger;
import exceptions.BadDataException;
import exceptions.BikeNotAvailableException;
import exceptions.ObjectNotFound;
import java.util.Scanner;
import java.util.logging.Level;
import lists.Lists;

public class Menu {
    
    public static Scanner in = new Scanner(System.in);
    
    
    public static void start(){
        
        int j =99;
        while ( j!= 0){
           Menu.showMenu();
           j = in.nextInt();
           switch (j){
               case 1:
                   Menu.showBikeMenu();
                   break;
               case 2:
                   Menu.showClientMenu();
                   break;
               case 3:
                   Menu.showReservationMenu();
                   break;
               case 4:
                   Menu.showLogMenu();
                   break;
               case 0:
                    break;
               default:
                   System.out.println("No option with entered id !");
                   break;
           }
        }
    }
    
    
    public static void showMenu() {

        System.out.println("MENU:");
        System.out.println("1 - manage BIKES ");
        System.out.println("2 - manage CLIENTS");
        System.out.println("3 - manage RESERVATIONS ");
        System.out.println("4 - turn on/off log report");
        System.out.println("0 - to exit");

    }
    
    public static void showLogMenu(){
        
        int j =99;
        while (j!=0){
                    
        System.out.println("LOG REPORT:");
        System.out.println("1 - turn on log reporting");
        System.out.println("2 - turn off log reporting");
        System.out.println("3 - set logging level");
        System.out.println("0 - main menu");
        
        j = in.nextInt();
        switch(j){
            case 1:
                MainLogger.activeLogger();
                break;
            case 2:
                MainLogger.deactivateLogger();
                break;
            case 3:
                System.out.println("SET LEVEL:");
                System.out.println("1 - WARNING");
                System.out.println("2 - INFO");
                System.out.println("... other");
                System.out.println("0 - logging menu");
                int g = in.nextInt();
                switch(g){
                    case 1:
                        MainLogger.changeLevel(Level.WARNING);
                        break;
                    case 2:
                        MainLogger.changeLevel(Level.INFO);
                        break;
                    case 0:
                        break;
                    default:
                        System.out.println("No option with entered number!");
                        break;
                                                    
                }
                break;
                
            case 0:
                break;
            default:
                System.out.println("No option with entered number!");
                 break;
                
        }
        
        }
    }
    
     public static void showBikeMenu() {

        int j = 99;
        while (j != 0) {

            System.out.println("BIKE MENU:");
            System.out.println("1 - add new bike");
            System.out.println("2 - delete bike from list");
            System.out.println("3 - sort bike list");
            System.out.println("4 - show bike list");
            System.out.println("0 - main menu");

            j = in.nextInt();
            switch (j) {

                case 1:
                    Lists.bList.add(ListHandling.BikeListHandling.addBike() );
                    break;
                case 2:
                    try {
                    ListHandling.BikeListHandling.deleteBike();
                    } catch (ObjectNotFound e){
                        System.out.println("No bike with specified ID !");
                    }
                    break;
                case 3:
                    ListHandling.BikeListHandling.sortBikeList();
                    break;
                case 4:
                    ListHandling.BikeListHandling.showBikeList();
                    break;
                case 0:
                    break;
                default:
                    System.out.println("No option with entered number!");
                    break;

            }
        }
    }
     
     
      public static void showClientMenu() {

        int j = 99;
        while (j != 0) {

            System.out.println("CLIENT MENU:");
            System.out.println("1 - add new client");
            System.out.println("2 - delete client from list");
            System.out.println("3 - sort client list");
            System.out.println("4 - show client list");
            System.out.println("0 - main menu");

            j = in.nextInt();
            switch (j) {

                case 1:
                    Lists.cList.add(ListHandling.ClientListHandling.addClient() );
                    break;
                case 2:
                    try {
                    ListHandling.ClientListHandling.deleteClient() ;
                    } catch ( ObjectNotFound e){
                        System.out.println("No client with specified ID!");
                    }
                    break;
                case 3:
                    ListHandling.ClientListHandling.sortClientList();
                    break;
                case 4:
                    ListHandling.ClientListHandling.showClientList();
                    break;
                case 0:
                    break;
                default:
                    System.out.println("No option with entered number!");
                    break;

            }
        }

    }
      
      
      
       public static void showReservationMenu() {

        int j = 99;
        while (j != 0) {

            System.out.println("RESERVATION MENU:");
            System.out.println("1 - make new reservation");
            System.out.println("2 - cancel reservation");
            System.out.println("3 - confirm reservation");
            System.out.println("4 - finalize reservation");
            System.out.println("5 - sort reservation list");
            System.out.println("6 - show reservation list");
            System.out.println("0 - main menu");

            j = in.nextInt();
      
              switch (j) {

                case 1:
                    try {
                        ListHandling.ReservationListHandling.addReservation();
                    } catch (BikeNotAvailableException e) {
                        System.out.println("Selected bike is not available !");
                    }
                    catch ( BadDataException e){
                        System.out.println("Entered data is not valid ! ( ID or Date )");
                    }
                    break;
                case 2:
                    try {
                        ListHandling.ReservationListHandling.cancelReservation();
                    } catch (BadDataException e) {
                        System.out.println("Reservation status is not valid to cancel !");
                    } catch (ObjectNotFound e){
                        System.out.println("No reservation with specified ID !");
                    }
                    break;
                case 3:
                    try {
                        ListHandling.ReservationListHandling.activeReservation();
                    } catch (BadDataException e) {
                        System.out.println("Reservation status is not valid to confirm !");
                    } catch (ObjectNotFound e){
                        System.out.println("No reservation with specified ID !");
                    }
                    break;
                case 4:
                    
                    try {
                        ListHandling.ReservationListHandling.finalizeReservation();
                    } catch (BadDataException e) {
                        System.out.println("Reservation status is not valid to finalize !");
                    } catch (ObjectNotFound e){
                        System.out.println("No reservation with specified ID !");
                    }
                    break;
                case 5:
                    ListHandling.ReservationListHandling.sort();
                    break;
                case 6:
                    ListHandling.ReservationListHandling.show();
                    break;
                case 0:
                    break;
                default:
                    System.out.println("No option with entered number!");
                    break;

            }
        }

    }
    
}
